const app = getApp();
const companyName = app.globalData.companyName;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    code: '',
    newPhone: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  inputCode: function(e) {
    this.setData({
      code: e.detail.value
    });
  },
  inputNewPhone: function(e) {
    this.setData({
      newPhone: e.detail.value
    });
  },
  getAdminCode: function() {
    const url = app.globalData.url;
    wx.request({
      url: url + '/management/codeByChangePhone',
      success: function(response) {
        if (response.data.success) {
          wx.showToast({
            title: '验证码已经发送到管理员手机,请注意查看',
            icon: 'none',
            duration: 3000
          });
        } else {
          wx.showToast({
            title: '提取验证码失败',
            icon: 'none'
          });
        }
      }
    })
  },
  save: function() {
    const url = app.globalData.url;
    const code = this.data.code;
    const newPhone = this.data.newPhone;
    wx.request({
      url: url + '/management/updatePhone',
      data: {
        code,
        newPhone,
        companyName
      },
      method: 'POST',
      success: function(response) {
        if (response.data.success) {
          wx.navigateBack({
            delta:1
          });
          wx.showToast({
            title: '修改成功',
            icon:'none'
          })
        }else{
          wx.showToast({
            title: response.data.message || '修改失败',
            icon: 'none'
          })
        }
      }
    })
  }
})